<?php
/**
 +------------------------------------------------------------------------------
 * ListAction控制器类
 +------------------------------------------------------------------------------
 * @category   view
 * @package  index
 * @subpackage  index
 * @author   朝闻道 <hydata@gmail.com>
 * @date  2010-8-22
 * @time  下午01:19:40
 +------------------------------------------------------------------------------
 */
 class ListAction extends CommonAction {
 	
 	/**
 	   *最近的列表
 	   *@date 2010-8-27
 	   *@time 上午11:28:34
 	   */
 	function index() {
 		//最近的列表
 		if(empty($_GET['id'])){
			$this->assign('lang',$this->plang['guo']);
			$arc=new Model();
			$condition=array();
			$condition['arc.is_show']="1";
			$condition['lang.lang']=$this->lang;
			$condition['arc.'.$this->plang['l'].'name']=array('neq','');
			$condition['_string']="FIND_IN_SET('".$this->lang."',arc.`olang`) > 0";
			$field="arc.*,lang.url as url,lang.about as about";
			$data_list=$arc->Table('iic_arc arc')->join("iic_arc_lang lang On arc.id=lang.aid")->Field($field)->where($condition)->order("arc.ctime DESC")->limit('0,20')->Select();
			$this->assign('list',$data_list);
			$this->clickorshow($data_list,'0');
	 		$this->display();
 		}else{
 			$id=Input::getVar($_GET['id']);
 			if($id=='1'){
 				$this->genernal();
 			}elseif($id=='2'){
 				$this->business();
 			}else{
	 			$dao=D("Cat");
	 			$info=$dao->find($id);
	 			unset($dao);
	 			if($info['topid']=='1'){
	 				$this->genernal();
	 			}else{
	 				$this->business();
	 			}
 			}
 		}
 	}//end index
 	
	/**
	 * @genernal
	 * @author   朝闻道 <hydata@gmail.com>
	 * @date:  2010-8-22 / time:  下午01:19:47
	 +------------------------------------------------------------------------------
	 */
	function genernal() {
		//genernal_genernal
		$pnum=empty($_GET['pn'])?"25":$_GET['pn'];
		$dao=new Model();
		$id=Input::getVar($_GET['id']);
		$pid=empty($id)?'2':$id;
		$is_show=1;
		$cat_in='';
		//获取子类
		$cat_son=$dao->Table('iic_cat')->where("pid=$pid AND topid='2' AND is_show='$is_show'")->order("rank DESC,ctime DESC")->findAll();
		if(empty($cat_son)){//如果无子类则获取同级类
			$cat_list=$dao->Table('iic_cat c1')->join("iic_cat c2 ON c1.pid=c2.pid")->where("c1.id=$id AND c1.topid='2' AND c1.is_show='$is_show'")->order("c1.rank DESC,c1.ctime DESC")->findAll();
			$cat_in=$id;
		}else{
			$cat_list=$cat_son;
			foreach ($cat_son as $cs){
				$cat_in.=$cs['id'].',';
			}
			$cat_in=trim($cat_in,',');
		}
		$arr=array();
		foreach ($cat_list as $v){//根据语言显示标题
			$v['title']=$v[$this->plang['l'].'name'];
			$arr[]=$v;
		}
		$this->assign('cat_list',$arr);

		
		$condition=array();
		$condition['arc.is_show']="1";
		$condition['arc.cid']=array('in',$cat_in);
		$condition['lang.lang']=$this->lang;
		//$condition['arc.is_'.$this->plang['guo']]="1";
		$condition['_string']="FIND_IN_SET('".$this->lang."',`olang`) > 0 ";
		
		$field="arc.*,lang.url as url,lang.about as about";
		$count=$dao->Table('iic_arc arc')->join("iic_arc_lang lang On arc.id=lang.aid")->Field($field)->where($condition)->order("arc.activetime DESC")->count();
		$page=new Page($count,$pnum);
		$page->config=array('header'=>'Rows','prev'=>'Previous','next'=>'Next','first'=>'«','last'=>'»','theme'=>' %nowPage%/%totalPage% %upPage% %downPage% %first%  %prePage%  %linkPage%  %nextPage% %end%');
		$this->assign('showpage',$page->show());
		$page->config=array('header'=>'','prev'=>'<','next'=>'>','first'=>'«','last'=>'»','theme'=>'%first% %upPage%  %prePage%  %linkPage%  %nextPage% %downPage% %end%');
		$this->assign('showpage_bot',$page->show_img());
		$limit=$page->firstRow.','.$page->listRows;
		$data_list=$dao->Table('iic_arc arc')->join("iic_arc_lang lang On arc.id=lang.aid")->Field($field)->where($condition)->order("arc.activetime DESC")->limit($limit)->Select();
		//dump($dao->getLastSql());
		$this->assign('list',$data_list);
		$this->clickorshow($data_list,'0');
		$this->assign('dh',$this->cat_dh($id,$this->plang['l']));
		
		
		$this->display();
	}//end genernal_genernal
	
	/**
	 * @商业频道首页
	 * @author   朝闻道 <hydata@gmail.com>
	 * @date:  2010-8-22 / time:  下午01:20:56
	 +------------------------------------------------------------------------------
	 */
	function business() {
		//buslness_商业频道首页
		$pnum=empty($_GET['pn'])?"25":$_GET['pn'];
		$dao=new Model();
		$id=Input::getVar($_GET['id']);
		$pid=empty($id)?'2':$id;
		$is_show=1;
		$cat_in='';
		//获取子类
		$cat_son=$dao->Table('iic_cat')->where("pid=$pid AND topid='2' AND is_show='$is_show'")->order("rank DESC,ctime DESC")->findAll();
		if(empty($cat_son)){//如果无子类则获取同级类
			$cat_list=$dao->Table('iic_cat c1')->join("iic_cat c2 ON c1.pid=c2.pid")->where("c1.id=$id AND c1.topid='2' AND c1.is_show='$is_show'")->order("c1.rank DESC,c1.ctime DESC")->findAll();
			$cat_in=$id;
		}else{
			$cat_list=$cat_son;
			foreach ($cat_son as $cs){
				$cat_in.=$cs['id'].',';
			}
			$cat_in=trim($cat_in,',');
		}
		$arr=array();
		foreach ($cat_list as $v){//根据语言显示标题
			$v['title']=$v[$this->plang['l'].'name'];
			$arr[]=$v;
		}
		$this->assign('cat_list',$arr);

		
		$condition=array();
		$condition['arc.is_show']="1";
		$condition['arc.cid']=array('in',$cat_in);
		$condition['lang.lang']=$this->lang;
		//$condition['arc.is_'.$this->plang['guo']]="1";
		$condition['_string']="FIND_IN_SET('".$this->lang."',`olang`) > 0 ";
		$field="arc.*,lang.url as url,lang.about as about";
		$count=$dao->Table('iic_arc arc')->join("iic_arc_lang lang On arc.id=lang.aid")->Field($field)->where($condition)->order("arc.activetime DESC")->count();
		$page=new Page($count,$pnum);
		$page->config=array('header'=>'Rows','prev'=>'Previous','next'=>'Next','first'=>'«','last'=>'»','theme'=>' %nowPage%/%totalPage% %upPage% %downPage% %first%  %prePage%  %linkPage%  %nextPage% %end%');
		$this->assign('showpage',$page->show());
		$page->config=array('header'=>'','prev'=>'<','next'=>'>','first'=>'«','last'=>'»','theme'=>'%first% %upPage%  %prePage%  %linkPage%  %nextPage% %downPage% %end%');
		$this->assign('showpage_bot',$page->show_img());
		$limit=$page->firstRow.','.$page->listRows;
		$data_list=$dao->Table('iic_arc arc')->join("iic_arc_lang lang On arc.id=lang.aid")->Field($field)->where($condition)->order("arc.activetime DESC")->limit($limit)->Select();
		$this->assign('list',$data_list);
		$this->clickorshow($data_list,'0');
		$this->assign('dh',$this->cat_dh($id,$this->plang['l']));
		
		
		$this->display("genernal");
	}//end buslness_商业频道首页
	
	/**
	 * @标签列表页
	 * @author   朝闻道 <hydata@gmail.com>
	 * @date:  2010-8-22 / time:  下午01:22:01
	 +------------------------------------------------------------------------------
	 */
	function tags() {
		//tags_标签列表页
	}//end tags_标签列表页
	
	/**
   *精彩推荐
   *@date 2010-8-27
   *@time 下午02:26:28
   */
	function popular() {
		//精彩推荐
		$this->assign('lang',$this->plang['guo']);
		$arc=new Model();
		$condition=array();
		$condition['arc.is_show']="1";
		$condition['lang.lang']=$this->lang;
		$condition['arc.'.$this->plang['l'].'name']=array('neq','');
		$condition['_string']="FIND_IN_SET('".$this->lang."',arc.`olang`) > 0";
		$field="arc.*,lang.url as url,lang.about as about";
		$data_list=$arc->Table('iic_arc arc')->join("iic_arc_lang lang On arc.id=lang.aid")->Field($field)->where($condition)->order("arc.click DESC")->limit('0,48')->Select();
		$this->assign('list',$data_list);
		$this->clickorshow($data_list,'0');
		$this->display();
	}//end popular
	
	/**
	   *随机页面
	   *@date 2010-12-9 / @time 下午07:14:28
	   */
	function random() {
		//随机页面
		$this->assign('lang',$this->plang['guo']);
		$arc=new Model();
		$condition=array();
		$condition['arc.is_show']="1";
		$condition['lang.lang']=$this->lang;
		$condition['arc.'.$this->plang['l'].'name']=array('neq','');
		$condition['_string']="FIND_IN_SET('".$this->lang."',arc.`olang`) > 0";
		$field="arc.*,lang.url as url,lang.about as about";
		$data_list=$arc->Table('iic_arc arc')->join("iic_arc_lang lang On arc.id=lang.aid")->Field($field)->where($condition)->limit('0,200')->Select();
		shuffle($data_list);
		$arr=array();
		$count=count($data_list);
		$count=$count<48?$count:48;
		for ($i=1;$i<$count;$i++){
			$arr[$i]=$data_list[$i];
		}
		$this->assign('list',$arr);
		$this->clickorshow($arr,'0');
		$this->display("List:popular");
	}//end random
	
	
}